package com.chuanjiabao.wisdom.ui.activity

import android.os.Bundle
import android.webkit.WebSettings
import com.chuanjiabao.wisdom.R
import com.chuanjiabao.wisdom.ui.BaseActivity
import kotlinx.android.synthetic.main.activity_detail.*

class DetailActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_detail)
        initView()
    }

    private fun initView() {
        val itemId = intent.getStringExtra("module_id")
        val isSecret = intent.getBooleanExtra("module_isSecret", false)

        llModuleWeb.apply {
            //支持javascript
            @Suppress("DEPRECATION")
            settings.javaScriptEnabled = true
            //设置可以支持缩放
            settings.setSupportZoom(true)
            //自适应屏幕
            settings.loadWithOverviewMode = true
            settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
            isHorizontalScrollBarEnabled = false

            //设置出现缩放工具
            settings.builtInZoomControls = false
            settings.displayZoomControls = false

            //设置是否使用缓存
            settings.setAppCacheEnabled(true)
            settings.domStorageEnabled = true
            setBackgroundColor(0)
        }

        llModuleFinish.setOnClickListener { onBackPressed() }

        val url = "http://home.zzwisdom.com/demo/index/imgdetail?id=${itemId}&type=${if (isSecret) "2" else "1"}"
        llModuleWeb.loadUrl(url)
    }

}
